'use strict';
let config=global.config || {};
const log4js=require("log4js");
const logger=log4js.getLogger();

let express = require('express')
    ,_ = require('lodash')
    ,util=require("util")
    ,fs = require('fs')
    ,path = require('path')
    ,bodyParser = require('body-parser');

let app = express();

let compression = require('compression');
app.use(compression());

let morganConfig=config.morgan || {};
if (morganConfig) {
    const morgan = require('morgan');
    app.use(morgan(morganConfig));
}

app.use(bodyParser.urlencoded({ extended: false ,limit: '500000000'}));
app.use(bodyParser.json({limit: '50000000'})); //解析POST的body数据有用
let cookieParser = require('cookie-parser');
app.use(cookieParser());

app.use(express.static(config.web.view));

app.use('/',require('./routes'));

app.use(function(req, res, next) {
    let err = new Error('Not Found');
    err.status = 404;
    res.status(404).send(err);
});

app.listen(config.web.port);
logger.info("启动完成");

module.exports = app;